﻿
using EntityModels.Entities;
using EntityModels.Normal;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace EntityModels.Configures
{
    /// <summary>
    /// 值生成和计算属性
    /// </summary>
    public class GeneratedValueEntityConfiguration : IEntityTypeConfiguration<GeneratedValueEntity>
    {
        public void Configure(EntityTypeBuilder<GeneratedValueEntity> builder)
        {
            builder.Property(g => g.Inserted).ValueGeneratedOnAdd().HasValueGenerator<NowTimeValueGenerator>();

            builder.Property(g => g.InsertedOffset).ValueGeneratedOnAddOrUpdate().HasValueGenerator<NowTimeValueGenerator>().HasDefaultValueSql("getdate()");

            builder.Property(g => g.Text).HasDefaultValue("Text");

            builder.Ignore(g => g.SummryInApp);

            builder.Property(g => g.SummryInDatabase)
        .HasComputedColumnSql("N'Record id is ' + convert(nvarchar, [Id]) + N' and inserted on ' + convert(nvarchar, [InsertedOffset]) + N' by database.'", true);

        }
    }
}
